package com.xjnt.frameworks.plugin.entity.naming;

import com.jfinal.kit.StrKit;

public class SimpleNameStyles {
	
	/**
	 * 默认:原样输出
	 */
	public static final INameStyle DEFAULT = new INameStyle() {
		
		@Override
		public String name(String className) {
			return className;
		}
	};
	
	/**
	 * 首字母小写
	 */
	public static final INameStyle FIRST_LOWER_CASE = new INameStyle() {
		
		@Override
		public String name(String className) {
			return StrKit.firstCharToLowerCase(className);
		}
	};
	
	/**
	 * 所有大写
	 */
	public static final INameStyle ALL_UPPER_CASE = new INameStyle() {
		
		@Override
		public String name(String className) {
			return className.toUpperCase();
		}
	};
	
	/**
	 * 所有小写
	 */
	public static final INameStyle ALL_LOWER_CASE = new INameStyle() {
		
		@Override
		public String name(String className) {
			return className.toLowerCase();
		}
	};
	
	/**
	 * 所有大写,并用下划线隔开
	 */
	public static final INameStyle ALL_UPPER_CASE_UNDERLINE = new INameStyle() {
		
		@Override
		public String name(String className) {
			String tableName = "";
            for (int i = 0; i < className.length(); i++) {
                char ch = className.charAt(i);
                if (i != 0 && Character.isUpperCase(ch)) {
                    tableName += "_" + ch;
                } else {
                    tableName += Character.toUpperCase(ch);
                }
            }
            return tableName;
		}
	};
	
	/**
	 * 所有小写,并用下划线隔开
	 */
	public static final INameStyle ALL_LOWER_CASE_UNDERLINE = new INameStyle() {
		
		@Override
		public String name(String className) {
			String tableName = "";
            for (int i = 0; i < className.length(); i++) {
                char ch = className.charAt(i);
                if (i == 0) {
                    tableName += Character.toLowerCase(ch);
                } else if (Character.isUpperCase(ch)) {
                    tableName += "_" + Character.toLowerCase(ch);
                } else {
                    tableName += ch;
                }
            }
            return tableName;
		}
	};
}
